<%@page import="classes.AccountManager"%>
<%@page import="classes.HomeWorkStudent"%>
<%@page import="classes.HomeworkManagerStudent"%>
<%@page import="classes.User"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Homeworks</title>
</head>
<body>
	<form
		action="showHomeworks.jsp?homework_id=<%=request.getParameter("homework_id")%>"
		method="post">
		<%
			HomeworkManagerStudent hmanager = (HomeworkManagerStudent) getServletContext()
					.getAttribute(HomeworkManagerStudent.HOMEWORKMANAGERSTUDENT);
			if (request.getParameter("mark") != null) {
				//if(request.getParameter("mark").equals(""))
				HomeworkManagerStudent.updateSomething(Integer.parseInt(request.getParameter("homework_id")),
						"mark", request.getParameter("mark"));
			}
			if (request.getParameter("comment") != null) {
				HomeworkManagerStudent.updateSomething(Integer.parseInt(request.getParameter("homework_id")),
						"comment", request.getParameter("comment"));
			}
		%>
		<center>
			<table border="15">
				<tr>
					<th>Student Name/Surname&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
					<th>Recieved Time&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
					<th>Download&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
					<th>Mark&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
					<th>Comment&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
				</tr>
				<%
					HomeWorkStudent[] homeworks = hmanager.getStudentHomework(Integer
							.parseInt(request.getParameter("homework_id")));
					AccountManager amanager = (AccountManager) getServletContext()
							.getAttribute(AccountManager.ACCOUNTMANAGER);
					for (int i = 0; i < homeworks.length; i++) {
						User user = amanager.getUser(AccountManager.getUsername(homeworks[i]
								.getStudentID()));
						String nameAndSurname = user.getName() + " "
								+ user.getSurName();
						out.println("<tr> " + "<td> " + nameAndSurname + "</td>"
								+ "<td>" + homeworks[i].getReceivedDate() + "</td>"
								+ "<td>" + "<a href =\""+  homeworks[i].getFile() + "\">Download file</a>" + "</td>" + "<td>"
								+ "<input type=\"text\" name=mark value="
								+ homeworks[i].getMark()
								+ "><input type=\"submit\" name=butt value=\"Set\">"
								+ "</td>" + "<td>" 
								+ "<input type=\"text\" name=comment value="
								+ homeworks[i].getComment()
								+ "><input type=\"submit\" name=butt value=\"Set\">"
								+ "</td>" + "</tr>");
					}
				%>
			</table>
		</center>
	</form>
</body>
</html>